//*************************************************************************************
/** \file ser_string.cpp
 *    This file contains a class which allows use of the set of overloaded left-shift 
 *    operators "<<" in base_text_serial.* to easily put all sorts of data into a 
 *    character buffer in a manner similar to strstreams in regular C++. 
 *
 *  Revised:
 *    \li 04-03-2006 JRR For updated version of compiler
 *    \li 06-10-2006 JRR Ported from C++ to C for use with some C-only projects; also
 *        serial_avr.h now has defines for compatibility among lots of AVR variants
 *    \li 08-11-2006 JRR Some bug fixes
 *    \li 03-02-2007 JRR Ported back to C++. I've had it with the limitations of C.
 *    \li 04-16-2007 JO  Added write (unsigned long)
 *    \li 07-19-2007 JRR Changed some character return values to bool, added m324p
 *    \li 01-12-2008 JRR Added code for the ATmega128 using USART number 1 only
 *    \li 02-14-2008 JRR Split between base_text_serial and rs232 files
 *    \li 05-31-2008 JRR Changed baud calculations to use CPU_FREQ_MHz from Makefile
 *    \li 06-01-2008 JRR Added getch_tout() because it's needed by 9Xstream modems
 *    \li 07-05-2008 JRR Changed from 1 to 2 stop bits to placate finicky receivers
 *    \li 12-22-2008 JRR Split off stuff in base232.h for efficiency
 *    \li 06-30-2009 JRR Received data interrupt and buffer added
 *    \li 11-20-2011 JRR Changed from serial port driver to string buffer filler upper
 *
 *  License:
 *    This file copyright 2006-2011 by JR Ridgely. It is released under the Lesser GNU
 *    public license, version 2. It is intended for educational use only, but it may
 *    be used for any purpose permitted under the LGPL. The author has no control 
 *    over the uses of this software and cannot be responsible for any consequences 
 *    of such use. 
 */
//*************************************************************************************

#include <stdint.h>
#include <stdlib.h>


//-------------------------------------------------------------------------------------
/** This method initializes the serial string object, saving a pointer to the buffer
 *  where data will be written and initializing the internal pointers. 
 *  @param p_the_buffer A pointer to the buffer where the data will be stored
 *  @param buffer_size The size of the buffer in which the data will be stored
 */

ser_string::ser_string (char* p_the_buffer, uint8_t buffer_size)
	: base_text_serial ()
{
	p_buffer = p_the_buffer;				// Save a copy of buffer pointer
	size = buffer_size;
	i_put = 0;								// Initialize the array indices
	i_get = 0;
	how_full = 0;
}


//-------------------------------------------------------------------------------------
/** This method writes one character into the character buffer. If the buffer is full,
 *  it waits for a while -- this is because often there is an interrupt service 
 *  routine which gets characters from the buffer, and this might free up some space.
 *  This routine times out after a while, though, if space doesn't become free. 
 *  @param chout The character to be sent out
 *  @return True if everything was OK and false if there was a timeout
 */

bool ser_string::putchar (char chout)
{
	
	return (true);
}


//-------------------------------------------------------------------------------------
/** This method writes all the characters in a string until it gets to the '\\0' at 
 *  the end. WARNING: This function blocks until it's finished. 
 *  @param str The string to be written 
 */

void ser_string::puts (char const* str)
{
	while (*str) putchar (*str++);
}


//-------------------------------------------------------------------------------------
/** This method gets one character from the string, if one is there.  If not, it
 *  waits until there is a character available.  This can sometimes take a long time
 *  (even forever), so use this function carefully.  One should almost always use
 *  check_for_char() to ensure that there's data available first. 
 *  @return The character which was found in the string buffer
 */

int16_t ser_string::getchar (void)
{
	uint8_t recv_char;						// Character read from the buffer

	return (recv_char);
}


//-------------------------------------------------------------------------------------
/** This method checks if there is a character in the character buffer. It returns 
 *  true if there's a character available and false if not. 
 *  @return True for character available, false for no character available
 */

bool ser_string::check_for_char (void)
{
}


//-------------------------------------------------------------------------------------
/** This operator returns the character at the given index into the buffer, with the
 *  oldest character in the buffer defining index 0. 
 *  @param index The index of the character to be returned
 */

char ser_string::operator [] (uint16_t index)
{
	return (0xFF);
}
